home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 52
/
Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso
/
Aminet
/
comm
/
irc
/
GGSearch.lha
/
GGSearch.amirx
next >
Wrap
Text File
|
2002-09-16
|
5KB
|
170 lines
/* GGSearch 1.4 ©2002 Michael Trebilcock */
Options Results
Parse Arg Command" "Args
Port=Address()
UCommand=Upper(Command)
IF UCommand~="SEARCH"&UCommand~="NEXT"|UCommand="SEARCH"&Args="" THEN Call ErrMsg("Usage: /GG <SEARCH/NEXT> [Query]")
Bold="02"x;Col="03"x
Res="0F"x;More="0"
IF UCommand="NEXT" THEN DO
Args=GetClip(GGSearch)
Next=GetClip(GGNext)
IF Next="" THEN Call ErrMsg("You haven't searched for anything yet!")
End
ELSE Call SetClip(GGSearch,Args)
Search=Translate(Args,"+"," ")
Desc=Search;Call FindRepl("& %26");Search=Desc
Call cEcho("Connecting to www.google.com, please wait..")
IF ~Open(TCP,"TCP:www.google.com/80","RW") THEN Call ErrMsg("Unable to connect, try again later..")
Call cEcho("Connected, searching for "Args)
IF UCommand="NEXT" THEN Call WriteLn(TCP,"GET "Next" HTTP/1.0")
ELSE Call WriteLn(TCP,"GET /search?q="Search"&btnG=Google+Search HTTP/1.0")
Call WriteLn(TCP,"User-Agent: GGSearch/1.4")
Call WriteLn(TCP,"Host: www.google.com")
Call WriteLn(TCP,"Referer: http://www.google.com/")
Call WriteLn(TCP,"")
IF Word(ReadLn(TCP),2)~="200" THEN Call Layout()
DO UNTIL Output="</script>"|EOF(TCP)
Output=ReadLn(TCP)
End
Call EOFCheck()
Call Pointer()
IF Pos("web page information",Output)>0 THEN DO
WebSite="1"
Call cEcho(Col"0,12Showing web page information for "Bold""Args""Bold)
i=1;To=1
Call CheckRes()
End
ELSE IF Pos(">Results <",Output)="0" THEN DO
DO UNTIL EOF(TCP)
Output=ReadLn(TCP)
IF Pos("did not match",Output)>0 THEN Call CloseTCP(Bold"End of Google search"Bold" - No matches found")
IF Pos("no information",Output)>0 THEN DO
DO UNTIL Pos("Find web pages",Output)>0|EOF(TCP)
Output=ReadLn(TCP)
End
Call EOFCheck()
Output2=SubStr(Output,Pos("HREF=",Upper(Output))+5)
Output2=Left(Output2,Pos(">",Output2)-1)
Call SetClip(GGNext,Output2)
Call cEcho(Bold"End of Google search"Bold" - No information available for URL "Bold""Args""Bold)
Call CloseTCP("Type /GG NEXT to find web pages that contain the term "Args)
End
End
End
Call EOFCheck()
Output2=Output
Output=SubStr(Output,Pos(">Results <",Output))
Output=Translate(Output,,"<>/b")
From=Word(Output,2);To=Word(Output,4)
Sites2=Word(Output,6);Sites=Word(Output,8)
Secs2=Word(Output,10);Secs=Word(Output,12)
IF Sites2="a" THEN Call cEcho(Col"0,12Results "Bold""From" - "To""Bold" of about "Bold""Sites""Bold". Search took "Bold""Secs""Bold" seconds."Res)
ELSE Call cEcho(Col"0,12Results "Bold""From" - "To""Bold" of "Bold""Sites2""Bold". Search took "Bold""Secs2""Bold" seconds."Res)
i=From
Output=Output2
CheckRes:
DO UNTIL i=To+1|EOF(TCP)
IF Pos("<p><a",Output)>0 THEN DO
Output2=SubStr(Output,Pos("<P><A HREF=",Upper(Output))+11)
Desc=SubStr(Output2,Pos(">",Output2)+1)
Desc=SubStr(Desc,1,Pos("</A>",Upper(Desc))-1)
Call FindRepl("<b> "Bold);Call FindRepl("</b> "Bold)
Call FindRepl("< <");Call FindRepl("> >")
Call FindRepl("& &");Call FindRepl("" "d2c(34))
Output2=SubStr(Output2,1,Pos(">",Output2)-1)
IF Left(Output2,5)="/url?" THEN DO
Output2=SubStr(Output2,Pos("q=",Output2)+2)
Output2=SubStr(Output2,1,Pos("&e=",Output2)-1)
End
Call cEcho(Bold""i""Bold". "Output2)
Call cEcho(Bold"^^"Bold Desc)
i=i+1
End
IF i<To+1 THEN Call Pointer()
End
Call EOFCheck()
IF WebSite="1" THEN DO
DO UNTIL Pos("contain the term",Output)>0|EOF(TCP)
Output=ReadLn(TCP)
End
IF EOF(TCP) THEN Call CloseTCP(Bold"End of Google search"Bold)
Output2=SubStr(Output,Pos("HREF=",Upper(Output))+5)
Output2=SubStr(Output2,1,Pos(">",Output2)-1)
Call SetClip(GGNext,Output2)
Call CloseTCP(Bold"End of Google search"Bold" - Type /GG NEXT to find web pages that contain the term "Args)
End
IF Right(To,1)="0" THEN DO
Call SetClip(GGNext,"/search?q="Search"&hl=en&lr=&start="To"&sa=N")
Call CloseTCP(Bold"End of Google search"Bold" - Type /GG NEXT for the next 10 results")
End
ELSE Call CloseTCP(Bold"End of Google search"Bold" - No more matches")
Exit
ErrMsg:
Call cEcho(Arg(1))
Exit
cEcho:
IF Port="REXX" THEN SAY "«GGSearch» "Arg(1)
ELSE "ECHO P="d2c(27)"b«GGSearch» TEXT="Arg(1)
Return 0
CloseTCP:
IF Arg(1)~="" THEN Call cEcho(Arg(1))
Call Close(TCP)
Exit
Layout:
Call cEcho(Bold"Error"Bold": Could not search for "Args)
Call cEcho("The page layout has possibly changed")
Call Close(TCP)
Exit
FindRepl:
Prstxt=Arg(1)
LFor=Word(Prstxt,1)
Length=Length(LFor)
Rplas=Word(Prstxt,2)
First="0"
DO UNTIL First="0"
First=Pos(LFor,Desc)
IF First>0 THEN DO
First2=SubStr(Desc,1,First-1)
Next=SubStr(Desc,First+Length)
Desc=First2""Rplas""Next
End
End
Return 0
EOFCheck:
IF EOF(TCP) THEN Call Layout()
Return 0
Pointer:
Output=""
DO UNTIL Pos("<p><a",Output)>0|EOF(TCP)
Output=Output""ReadCh(TCP,25)
End
Output2=""
DO UNTIL Pos("<br>",Output2)>0|EOF(TCP)
Output2=Output2""ReadCh(TCP,25)
End
Output=Output""Output2
Call EOFCheck()
Return 0